import wepy from 'wepy'
import Wx from '../common/wxApi'

import { connect } from 'wepy-redux'


@connect({
  userInfo (state) {
    return state.counter.userInfo
  },
  globalData (state) {
    return state.counter.globalData
  },
  city(state){
    return state.counter.city
  }
})
export default class Mixin extends wepy.mixin {

  methods = {
    //跳转路由
    navTo( url='' ){
      wepy.navigateTo({ url });
    },
    // 配合使用 button.login-btn(wx:if="{{!userInfo}}" open-type="getUserInfo" bindgetuserinfo="onGotUserInfo" data-fn="loginCallBack")
    onGotUserInfo(e) {
      Wx.promiseApi(wx.getSetting)
      .then(res=>{
        if(!res.authSetting['scope.userInfo'])
        {
          wepy.showToast({
            title: '请授权登录', 
            icon: 'none', 
          })
          return
        }
        else
        {
          if (!this.userInfo) {
            // GlobalApi.wxLogin({jsonData: e.detail}).then(data => {
            //   if (data && e.target.dataset.fn) {
            //     this[e.target.dataset.fn]()
            //   }
            // })
          }
        }
      })
      .catch(err=>{
        console.log(error)
      })
      
    }
  }
}
